API


Posted by mijouhsieh on 2023-04-09

axios

JS 函式庫

重要功能:

  • 廣泛browser支持
  • 可支援Node.js從後端發送HTTP Request => axios可用於前後端專案
  • 直接將JSON資料,轉換為JS物件,做回應(很方便!)

使用語法

透過axios發送GET請求

axios.get('api網址')
    .then(function (response) {
    //成功取得response物件後,要執行的事
    })
    .catch(function (error) {
    //處理發生錯誤狀況
    })
    .then(function (error) {
    //always executed
    })
第2個 .then 是選擇性的元件,無論請求是否成功,都會執行。

Ajax (Asynchrnous JavaScript and XML)

使用axios發出請求時,背後的技術是Ajax。

  • 發送非同步請求。
  • 資料格式: XML、JSON(較流行)。

#API #Axios #GET request







Related Posts

CSS-[網頁設計準則]-#1. Typography 文字排版

CSS-[網頁設計準則]-#1. Typography 文字排版

DAY43:Adding Big Numbers

DAY43:Adding Big Numbers

[C#] 檢查 Sql Injection 非法字元

[C#] 檢查 Sql Injection 非法字元


Comments